package org.bao.bestmatch;

import java.util.LinkedList;

import org.bao.bestmatch.model.Module;

/**
 * check the integrity and correctness of data in MS-EXCEL files.
 * assure input correct data to the next process.This is NOT necessary is you 
 * are sure that data you provided are complete correct.
 * @author baoxiwu<bb@feijiao.info>,Cell&Module,BOE DT
 * @version 0.9.0
 * @since 2010-11-22
 * @license LGPL
 * 
 */
public class DataChecker {
	public boolean isCorrect(LinkedList<Module> tfts, LinkedList<Module> cfs){
		//check TFT
		int size = -1;
		
		for(int i = 0; i < tfts.size(); i++){
			//check grade length,assure they are all with a same length.
			if(i == 0){
				size = tfts.get(i).getGrade().length();
			}
			else{
				if(size != tfts.get(i).getGrade().length()){
					return false;
				}
			}
			
			//ONLY '1' or '0' allowed in grade.
			for(int j = 0 ; j < tfts.get(i).getGrade().length(); j++){
				char str = tfts.get(i).getGrade().charAt(j);
				
				if(!(str == 'X') && !(str == 'O')){
					return false;
				}
			}
		}
		
		
		//check CF
		for(int i = 0; i < cfs.size(); i++){
			//check grade length,assure they are all with a same length.
			if(i == 0){
				size = cfs.get(i).getGrade().length();
			}
			else{
				if(size != cfs.get(i).getGrade().length()){
					return false;
				}
			}
			
			//ONLY '1' or '0' allowed in grade.
			for(int j = 0 ; j < cfs.get(i).getGrade().length(); j++){
				char str = cfs.get(i).getGrade().charAt(j);
				
				if(!(str == 'X') && !(str == 'O')){
					return false;
				}
			}
		}
		
		
		//check TFT and CF,assure that they can match with each other.
		//with above processes, all TFT/CF panels's grade have the same length 
		if(tfts.get(0).getGrade().length() != cfs.get(0).getGrade().length()){
			return false;
		}
		
		return true;
	}
}
